<template>
  <div class="contrain">
    <HeadTitle :left="true"
               :right="true"
               @back="back">
      <template v-slot:right>
        <h1>我收藏的帖子</h1>
      </template>
    </HeadTitle>
    <div class="Invis"
         v-show="!isLoading">
      <van-empty description="你还没有收藏过任何帖子"
                 v-if="LikeList.length === 0" />
      <div v-for="(item, i) in LikeList"
           :key="i">
        <Invi :main=item
              @click="goInvi(item._id)" />
      </div>
    </div>
  </div>
</template>

<script>
import HeadTitle from '_c/utils/HeadTitle.vue'
import Invi from '_c/Forum/Invitations.vue'
import { getLike } from '@/api/myself'
export default {
  components: { HeadTitle, Invi },
  data () {
    return {
      LikeList: [],
      isLoading: true
    }
  },
  methods: {
    back () {
      this.$router.push('/myself')
    },
    fetch () {
      const toast = this.$toast.loading({
        duration: 0,
        forbidClick: true,
        message: '加载中'
      })
      getLike(this.$store.state.User.user._id).then(res => {
        this.LikeList = res.data.likes
        this.isLoading = !this.isLoading
        toast.clear()
      }).catch(() => {
        toast.clear()
        this.$router.push('/myself')
      })
    }
  },
  created () {
    this.fetch()
  }
}
</script>

<style lang="less" scoped>
.Invis {
  padding: 0 10px;
  margin-top: 80px;
  div {
    margin-bottom: 10px;
  }
}
</style>
